﻿using HalconDotNet;

namespace Wpf.Halcon.Demo
{
    public static class DrawingObjectExtensions
    {

        public static HObject GenHObject(this HDrawingObjectInfo hDrawingObjectInfo)
        {
            HObject hObject = null;
            switch (hDrawingObjectInfo.Type)
            {
                case "rectangle1":
                    HOperatorSet.GenRectangle1(out hObject, hDrawingObjectInfo.HTuples[0], hDrawingObjectInfo.HTuples[1], hDrawingObjectInfo.HTuples[2], hDrawingObjectInfo.HTuples[3]);
                    break;
                case "circle":
                    HOperatorSet.GenCircle(out hObject, hDrawingObjectInfo.HTuples[0], hDrawingObjectInfo.HTuples[1], hDrawingObjectInfo.HTuples[2]);
                    break;
            }
            return hObject;
        }

        public static HTuple[] GetHTuples(this HDrawingObject drawingObject)
        {
            HTuple[] hTuple = null;
            string type = drawingObject.GetDrawingObjectParams("type");

            switch (type)
            {
                case "rectangle1":
                    {
                        hTuple = new HTuple[4];
                        hTuple[0] = drawingObject.GetDrawingObjectParams("row1");
                        hTuple[1] = drawingObject.GetDrawingObjectParams("column1");
                        hTuple[2] = drawingObject.GetDrawingObjectParams("row2");
                        hTuple[3] = drawingObject.GetDrawingObjectParams("column2");
                    }
                    break;
                case "circle":
                    {
                        hTuple = new HTuple[3];
                        hTuple[0] = drawingObject.GetDrawingObjectParams("row");
                        hTuple[1] = drawingObject.GetDrawingObjectParams("column");
                        hTuple[2] = drawingObject.GetDrawingObjectParams("radius");
                    }
                    break;
            }
            return hTuple;
        }

    }
}
